<script type="text/javascript"><!--//--><![CDATA[//><!--

	

    $(document).ready(function() {
        // Setup Form
		$('#form_master').setupForm([
            { name: 'id_permintaan', type: 'text', size: 'long', maxlength: 100, noempty:true, readonly:true},
			{ name: 'tanggal', type: 'date', size: 'short', maxlength: 200, noempty:true, value:new Date()},
            { name: 'nama', type: 'text', size: 'long', maxlength: 200},
            { name: 'departemen', type: 'lov', size: 'short',
                onClearButton:function(){
                    $(this).setval(''); 
                    $('#nama_departemen').setval(''); 
                },
                onActionButton:function(){ 
                    LOVDepartemen({ onSelect:function(row){ 
                        $('#departemen').setval(row.id_departemen_pk); 
                        $('#nama_departemen').setval(row.nama_departemen); 
                    } }); 
                }
            },
            { name: 'nama_departemen', type: 'text', size: 'medium', maxlength: 200, readonly:true},
            { name: 'permohonan_masalah', type: 'textarea', size: 'long', maxlength: 200, noempty:true}
        ],<?php echo json_encode($data) ?>); 
        
//		f_set_combo_city_code();
		
        <?php if($mode=="edit"){ ?>
        $('#id_permintaan').readonly();
        <?php } ?>

        <?php if($mode=="create"){ ?>
        $('#id_permintaan').setval('<?php echo $numb_id; ?>');
        <?php } ?>
		
		// Set Action Button
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
                            perbaikan = ($('#perbaikan')[0].checked == true) ? $('#perbaikan')[0].value : '';
                            penambahan = ($('#penambahan')[0].checked == true) ? $('#penambahan')[0].value : '';
                            pembelian_pengadaan_baru = ($('#pembelian_pengadaan_baru')[0].checked == true) ? $('#pembelian_pengadaan_baru')[0].value : '';
                            pemeliharaan = ($('#pemeliharaan')[0].checked == true) ? $('#pemeliharaan')[0].value : '';
                            penggantian_baru = ($('#penggantian_baru')[0].checked == true) ? $('#penggantian_baru')[0].value : '';
                            peminjaan_alat = ($('#peminjaan_alat')[0].checked == true) ? $('#peminjaan_alat')[0].value : '';

                            pilihan_permintaan = perbaikan+','+penambahan+','+pembelian_pengadaan_baru+','+pemeliharaan+','+penggantian_baru+','+peminjaan_alat;
                            $('#pilihan_permintaan').setval(pilihan_permintaan);
							$('#form_master').submitForm(	'/'+controller+'/ajax_post', 
															{	/*detail:[{ table: 'dtl_sample2', field:['index_no','ref_key_combo','ref_key_lov','jumlah','keterangan']}
																		],*/ 
																onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/Index');/*loadPage('/'+controller+'/edit/?id_permintaan='+(oData.genid!='' ? oData.genid : $('#id_permintaan').getval()));*/ }
															} 
														);
						}},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
		setAction(buttons);
		
		// Create Tab
		$('#tt').tabs({ border:false });  
		
		// Focus at First Object
		$('#form_master').focusFirst();


       // Setup Datagrid

        var grid_reload_detail = function() {
            $('#datagrid').datagrid('reload', $('#fm_search_detail').serializeObject());
        };

        id_permintaan = $('#id_permintaan');
        id = id_permintaan[0].value;

        $('#datagrid').datagrid({  
            url:gs_path+'/'+controller+'/getdata_detail/'+id, 
            queryParams: $('#fm_search_detail').serializeObject(),
            height:450,
            pagination:true,
            //singleSelect:true,
            columns:[[
                { field : 'ck', checkbox:true, width: 40, align: 'center' },
                { field : 'no', title : 'No', width : 150, sortable:true },
                { field : 'nama_barang', title : 'Nama Barang', width : 150, sortable:true },
                { field : 'jumlah', title : 'Jumlah', width : 150, sortable:true },
                { field : 'lokasi', title : 'Lokasi', width : 250,  sortable:true },
                { field : 'keterangan', title : 'Keterangan', width : 120, sortable:true }
            ]]
        });
        
    });

    function create_detail() {
        id_permintaan = $('#id_permintaan');
        id = id_permintaan[0].value;
        loadPage(gs_path + '/' + controller + '/create_detail/'+id);
    }

    function edit_detail() {
        var oSel = $('#datagrid').datagrid('getSelected');
        if (oSel == null) {
            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
        } else {
            loadPage(gs_path + '/' + controller + '/edit_detail/'+id+'?id_permintaan_dtl='+urlencode(oSel.id_permintaan_dtl));
        } 

    }

    function dalate_detail() {
        var oSel = $('#datagrid').datagrid('getSelected'); 
        if (oSel == null) { 
            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
        } else { 
            loadPage(gs_path + '/' + controller + '/ajax_delete_detail/'+id+'?id_permintaan_dtl='+urlencode(oSel.id_permintaan_dtl));
        } 
    }
//--><!]]></script>

<?php 
if (isset($data['pilihan_permintaan'])) {
    $arr_pilihan_permintaan = explode(',', $data['pilihan_permintaan']);

    $perbaikan_checked = ($arr_pilihan_permintaan[0] != '') ? 'checked' : '';
    $penambahan_checked = ($arr_pilihan_permintaan[1] != '') ? 'checked' : '';
    $pembelian_pengadaan_baru_checked = ($arr_pilihan_permintaan[2] != '') ? 'checked' : '';
    $pemeliharaan_checked = ($arr_pilihan_permintaan[3] != '') ? 'checked' : '';
    $penggantian_baru_checked = ($arr_pilihan_permintaan[4] != '') ? 'checked' : '';
    $peminjaan_alat_checked = ($arr_pilihan_permintaan[5] != '') ? 'checked' : '';
} else {
    $perbaikan_checked = '';
    $penambahan_checked = '';
    $pembelian_pengadaan_baru_checked = '';
    $pemeliharaan_checked = '';
    $penggantian_baru_checked = '';
    $peminjaan_alat_checked = '';
}
?>
<div id="form_master_message" style="display:none;"></div>
    <table class="tb_detail_form_detail" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">ID Permintaan Perangkat</td>
        <td colspan="2"><input id="id_permintaan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal</td>
        <td colspan="2"><input id="tanggal" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px"><b>Informasi Pemohon :</b></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama</td>
        <td colspan="2"><input id="nama" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Departement</td>
        <td colspan="2"><input id="departemen" /><input id="nama_departemen" name="nama_departemen" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px"><b>Pilih Permintaan Anda :</b> <input type="hidden" name="pilihan_permintaan" id="pilihan_permintaan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:300px"><input type="checkbox" id="perbaikan" value="perbaikan" <?php echo $perbaikan_checked; ?>>Perbaikan</td>
        <td class="label" style="width:300px"><input type="checkbox" id="penambahan" value="penambahan" <?php echo $penambahan_checked; ?>>Penambahan</td>
    </tr>
    <tr>
        <td class="label" style="width:300px"><input type="checkbox" id="pembelian_pengadaan_baru" value="pembelian_pengadaan_baru" <?php echo $pembelian_pengadaan_baru_checked; ?>>Pembelian/Pengadaan Baru</td>
        <td class="label" style="width:300px"><input type="checkbox" id="pemeliharaan" value="pemeliharaan" <?php echo $pemeliharaan_checked; ?>>Pemeliharaan</td>
    </tr>
    <tr>
        <td class="label" style="width:300px"><input type="checkbox" id="penggantian_baru" value="penggantian_baru" <?php echo $penggantian_baru_checked; ?>>Penggantian Baru</td>
        <td class="label" style="width:300px"><input type="checkbox" id="peminjaan_alat" value="peminjaan_alat" <?php echo $peminjaan_alat_checked; ?>>Peminjaman Alat</td>
    </tr>
    <tr>
        <td class="label" colspan="4" style="width:300px"><b>Silahkan sebutkan permohonan atau menjelaskan masalah yang terjadi :</b></td>
    </tr>
    <tr>
        <td colspan="4"><input id="permohonan_masalah" /></td>
    </tr>
    <tr>
        <td class="label" colspan="4" style="width:300px"><b>Daftar barang (sesuai list permintaan) :<?php if($mode=='create'){ ?><br>* Simpan Terlebih dahulu Data Permintaan Perangkat Untuk dapat menambah Daftar barang.<?php } ?></b></td>
    </tr>
</table>

<div id="tb_detail" style="padding:5px;height:auto;">
    <div>
        <form id="fm_search_detail" onsubmit="grid_reload_detail(); return false;">
            <table class="tb_detail_form_detail" style="margin-bottom:0px">
                <tr>
                    <td>
                        <?php if($mode=='edit'){ ?>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="create_detail()">Add</a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="edit_detail()">Edit</a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-delete" onclick="dalate_detail()">Delete</a>
                        <?php } ?>
                    </td>
                    <td>
                        <?php if($mode=='edit'){ ?>
                        <input type="text" id="keyword_detail" name="keyword_detail" class="textfield medium" />
                        <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload_detail(); return false;">Search by Keyword</a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-blank-file" onclick="$('#fm_search_detail').resetForm(); return false;">Reset</a>
                        <?php } ?>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<?php if($mode=='edit'){ ?>
<div id="datagrid" toolbar="#tb_detail"></div>
<?php } ?>